﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Practices.ESB.Adapter;
using Microsoft.BizTalk.Message.Interop;
using Microsoft.Practices.ESB.Exception.Management;

namespace BizTalk.ESB.Extensions.AdapterProviders
{
    public class WssAdapterProvider : BaseAdapterProvider
    {
        public override string AdapterName
        {
            get { return "Windows SharePoint Services"; }
        }

        public override string AdapterContextPropertyNamespace
        {
            get
            {
                return "WSS";
            }
        }

        protected override void SetEndpointContextProperties(IBaseMessageContext pipelineContext, string endpointConfig)
        {
            try
            {
                if (!string.IsNullOrEmpty(endpointConfig))
                {
                    AdapterMgr.SetContextProperties(pipelineContext, endpointConfig, this.AdapterName, this.AdapterContextPropertyNamespace);
                }
                else
                {
                    string defaultEC = this.GetDefaultEndpointConfig();
                    if (!string.IsNullOrEmpty(defaultEC))
                    {
                        AdapterMgr.SetContextProperties(pipelineContext, defaultEC, this.AdapterName, this.AdapterContextPropertyNamespace);
                    }
                }
            }
            catch (Exception ex)
            {
                EventLogger.Write("Windows SharePoint Services::SetEndpointContextProperties threw an exception\n{0}", ex.ToString());
            }
        }
    }
}
